package com.example.andr.byinvitationonly;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Toast;

import com.example.andr.byinvitationonly.modelo.Contacto;


public class MainActivity extends Activity {

    private boolean isChecked = false;
    private MenuItem item;
    private Contacto contacto;

    public MainActivity() {
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        //obterContactoUtilizador();
    }

    private void obterContactoUtilizador() {
        contacto = new Contacto("Andre", "and.estg@gmail.com");
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_i_am_here) {
            inverteCheckIn(item);
            return true;
        }

        return super.onOptionsItemSelected(item);
    }

    private void inverteCheckIn(MenuItem item) {
        if (isChecked == false) {
            if (this.contacto != null && !this.contacto.getEmail().isEmpty() && !this.contacto.getNome().isEmpty()) {
                isChecked = true;
                item.setIcon(R.drawable.ic_action_group);
                Intent intent = new Intent(this, ParticipantesLista.class);
                intent.putExtra(ParticipantesLista.IS_CHECKED_IN, isChecked);
                startActivity(intent);
            } else {
                Toast.makeText(this, "Dados incompletos", Toast.LENGTH_SHORT).show();
            }
        } else {
            isChecked = false;
            item.setIcon(R.drawable.ic_action_alone);
        }
    }


}
